<?php
	Class Md_user extends CI_Model{
		function insert_user($data){
			$this->db->insert("user",$data);
			return $this->db->insert_id();
		}
		function active_user($user_id){
			$this->db->where('user_id',$user_id);
			$this->db->update("user",array('is_actived'=>1));
		}
		function check_exists($username,$pass){
			$this->db->where('username',$username);
			if ($pass != ""){
				$this->db->where('password',$pass);
			}		
			
			$total_rec=  $this->db->count_all_results('user');	
			if ($total_rec > 0){
				return 1;
			}else{
				return 0;
			}
		}
		
		function check_email_exists($email){
			$this->db->where('email',$email);
			
			$total_rec=  $this->db->count_all_results('user');	
			if ($total_rec > 0){
				return 1;
			}else{
				return 0;
			}
		}
		function get_user($username,$pass){
			$this->db->where('username',$username);
			$this->db->where('password',$pass);
			$this->db->where('is_actived',1);
			
			$data= $this->db->get("user");
			$row = "";
			if ($data->num_rows() > 0)
			{
			   $row = $data->row(); 
			   
			}
			return $row;
		}
		function get_sodo_user($user_id){
			$this->db->where('user_id',$user_id);
			
			$data= $this->db->get("user_sodo ");
			$row = "";
			if ($data->num_rows() > 0)
			{
			   $row = $data->row(); 
			   
			}
			return $row;
		}
		function insert_sodo_user($data){
			$this->db->query("delete from user_sodo where user_id = ".$data['user_id']);
			$this->db->insert('user_sodo',$data);
		}
		function update_sodo_user($data){
			$this->db->where('user_id',$data['user_id']);
			$this->db->update('user_sodo',$data);
		}
	}
?>